package com.jsmile.cloud.authc.sys.repo;

import java.util.Optional;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsmile.cloud.authc.api.exception.AuthcException;
import com.jsmile.cloud.authc.sys.dao.SysResourcesDao;
import com.jsmile.cloud.authc.sys.model.SysResources;

import lombok.extern.slf4j.Slf4j;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 为了薪资破万，还是睡一会儿吧...!
 * @date 2020年10月16日 02:46:20
 */
@Service
@Slf4j
@Transactional(readOnly = false, rollbackFor = Exception.class)
public class SysResourcesRepository extends ServiceImpl<SysResourcesDao, SysResources> {

    /**
     * desc:删除资源
     *
     * @return
     */
    public boolean deleteResources(Long resourcesId) {
        Optional.ofNullable(resourcesId).orElseThrow(() -> new AuthcException("资源id不能为空!"));
        int i = this.baseMapper.delete(Wrappers.<SysResources>lambdaQuery().eq(SysResources::getParentId, resourcesId));
        i += baseMapper.deleteById(resourcesId);
        return retBool(i);
    }
}
